import { MainResponseType, buyListType } from "@/common/model/response";
import request from "@/utils/axios";

const URL = {
  getCurrencyPrice: "swap/getCurrencyPrice", //获取币种价格
  getSaleList: "market/getSaleList", //交易清单
  getBuyList: "market/getBuyList", //挂买清单
  order: "market/order", //挂卖股票币
  orderBuy: "market/orderBuy", //挂单股本金
  getData: "market/getData", //获取市场数据
  getMatchList: "market/getMatchList", //C2C交易记录
};

export function getCurrencyPrice(data: { number: string; currency: string }) {
  return request.get<
    any,
    MainResponseType<{
      last_price: string;
      chart_data: {
        currency: string;
        price: number;
        create_time: number;
        change_percent: string;
        gap: string;
      }[];
    }>
  >(URL.getCurrencyPrice, {
    params: {
      ...data,
    },
  });
}
export function getSaleList(data: { type: "mine" | "market"; page: string }) {
  return request.get<
    any,
    MainResponseType<
      buyListType<
        {
          order_id: number;
          amount: number;
          amount_matched: number;
          order_status: number;
          currency: string;
          create_time: string;
          order_sn: string;
          amount_left: number;
          price: number;
        }[]
      >
    >
  >(URL.getSaleList, {
    params: {
      ...data,
    },
  });
}
export function getBuyList(data: { page: string }) {
  return request.get<
    any,
    MainResponseType<
      buyListType<
        {
          order_id: number;
          amount: number;
          amount_matched: number;
          order_status: number;
          currency: string;
          create_time: string;
          order_sn: string;
          amount_left: number;
          order_status_name: string;
        }[]
      >
    >
  >(URL.getBuyList, {
    params: {
      ...data,
    },
  });
}
export function order(data: {
  APITOKEN: string;
  currency: string;
  amount: string;
  password: string;
}) {
  return request.post<any, MainResponseType<string>>(URL.order, data);
}
export function orderBuy(data: {
  APITOKEN: string;
  currency: string;
  amount: string;
  password: string;
}) {
  return request.post<any, MainResponseType<string>>(URL.orderBuy, data);
}
export function getData() {
  return request.get<
    any,
    MainResponseType<{
      price: number;
      balance: number;
      min_amount: number;
      max_amount: number;
      amount_on_sale: number;
      amount_macthed: number;
      amount_macthed_market: number;
    }>
  >(URL.getData);
}

export enum MatchEnum {
  buyer = "buyer",
  seller = "seller",
}
export function getMatchList(data: { page: string; type: MatchEnum }) {
  return request.get<
    any,
    MainResponseType<
      buyListType<
        {
          currency_sale: string;
          create_time: string;
          currency_buy: string;
          sale_amount: number;
          total_price: number;
          price: number;
        }[]
      > & {
        total_sell: number;
        total_buy: number;
        balnace: number;
      }
    >
  >(URL.getMatchList, {
    params: {
      ...data,
    },
  });
}
